import request from '@/utils/request';

/**
 * 获取tree
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getGoodsCategoryTree = () => {
  return request<API.goodsCategory.TreeSchema[]>({
    url: '/admin/category/tree',
    method: 'get'
  });
};

/**
 * 添加
 *
 * @param data: Permission
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const addGoodsCategory = (data: any) => {
  return request({
    url: '/admin/category',
    method: 'post',
    data
  });
};

/**
 * 编辑
 *
 * @param id
 * @param data: Permission
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateGoodsCategory = (id: number, data: any) => {
  return request({
    url: '/admin/category/' + id,
    method: 'put',
    data
  });
};

/**
 * 更新switch状态
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateSwitch = (id: number, data: { state?: boolean }) => {
  return request({
    url: `/admin/category/switch/${id}`,
    method: 'put',
    data
  });
};

/**
 * 删除
 *
 * @param id
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const deleteGoodsCategory = (id: number) => {
  return request({
    url: '/admin/category/' + id,
    method: 'delete'
  });
};
